﻿using System;
using System.Collections.Generic;
using System.Text;
using YouHP.Model;
using YouHP.BLL;
using YouHP.Utility;
using YouHP.Model.Group;
using System.Web;

namespace YouHP.Pages.Group
{
    public class Group:GroupBasePage
    {

        protected List<GroupUserInfo> mGroupAdminList;
        protected List<GroupUserInfo> mGroupActivestList;
        protected List<TopicInfo> mTopicList;

        protected int _pageSize =10;
        protected int _pageIndex =1;
        protected int _pageCount = 0;
        protected int _firstpage = 1;
        protected int _prevpage;
        protected int _nextpage;
        protected int n = 5;
        protected int _topicCount;
        protected string PagingString;
        protected string MemPagingString;


        protected string creattime;
        protected string  state;

        protected UserInfo GroupMasterData;
        protected List<GroupUserInfo> GroupAdminData;
        protected List<GroupUserInfo> MemberList;
        protected int _memberCount = 0;

        protected override void ShowPage()
        {
            base.ShowPage();
            if (ErrorCount > 0) return;

            this.AddLocation("病友小圈子", "/Group/Index.aspx");
            this.AddLocation(GroupData.GroupName, "/Group/Group.aspx?gid={gid}");
            this.SetTitle("病友小圈子");
            this.AddCommonJS();


            //增加点击数
            GroupBLL.Instance.IncreaseGroupHits(gid);

            //圈主
            GroupMasterData = UserBLL.Instance.GetUserInfo(GroupData.AppUserId);

            //管理员列表
            GroupAdminData = GroupUserBLL.Instance.GetGroupUserListAdmin(gid);

            //普通成员列表
            MemberList = GroupUserBLL.Instance.GetGroupUserListMember(GroupData.Id, _pageSize, _pageIndex, out _memberCount);
       
            //圈子最活跃用户列表
            mGroupActivestList = GroupUserBLL.Instance.GetGroupUserListActivest(gid, n);


             _pageIndex = RequestTools.GetQueryInt("page", 1);

            mTopicList = TopicBLL.Instance.GetTopicList(gid, _pageSize, _pageIndex, out _topicCount);
            _pageCount = Utils.GetPageCount(_topicCount, _pageSize);

            string query = HttpContext.Current.Request.Url.Query;
            query = Utils.RemoveQueryItem(query, "page");

            PagingString = this.GetPagingString(_pageIndex, _pageCount,
                "/Group/Group.aspx" + query, "page");


        }

        protected bool CanJoin()
        {
            if (GroupUserData.Role != Constants.RoleCreator && GroupUserData.Role != Constants.RoleAdmin && GroupUserData.Role != Constants.RoleMember && GroupUserData.Role != Constants.RoleAppling && GroupUserData.Role != Constants.RoleBlacklist)
                return true;
            else
                return false;
        }
        protected bool CanAddTopic()
        {
            if ((GroupUserData.Role == Constants.RoleAdmin) || (GroupUserData.Role == Constants.RoleCreator) || (GroupUserData.Role == Constants.RoleMember))
                return true;
            else
                return false;
        }
        protected bool CanAdmin()
        {
            if ((GroupUserData.Role == Constants.RoleCreator) || (GroupUserData.Role == Constants.RoleAdmin))
                return true;
            else
                return false;
        }
        protected bool CanInvite()
        {
            if ((GroupUserData.Role == Constants.RoleCreator) || (GroupUserData.Role == Constants.RoleAdmin))
                return true;
            else
                return false;
        }
          
    }
}
